/* GUI CONVERTED from repksrup.p (converter v1.75) Fri Jun 22 15:25:30 2001 */
/* repksrup.p - UPDATE sr_wkfl MULTI LINE ENTRY WITH TRANSFER VALIDATION    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.7.1.6 $                                                         */
/*V8:ConvertMode=Maintenance                                                */
/* REVISION: 8.5          CREATED: 10/31/96 BY: *G2HG* Julie Milligan       */
/* REVISION: 8.5    LAST MODIFIED: 02/13/97 BY: *G2L1* Julie Milligan         */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/26/99   BY: *J3M5* G. Latha           */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 05/12/00   BY: *N09X* Antony Babu        */
/* REVISION: 9.1      LAST MODIFIED: 07/12/00   BY: *N0G4* Katie Hilbert      */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* $Revision: 1.7.1.6 $    BY: Hualin Zhong   DATE: 06/13/01 ECO: *N0ZF*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* CREATED FROM icsrup.p */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter base_site like si_site.
define input parameter base_location like sr_loc no-undo.
define input parameter use-to-loc-status like mfc_logical no-undo.
define input parameter trnbr like lot_nbr.
define input parameter trline like lot_line.
define input-output parameter lotnext like wo_lot_next.
define input parameter singlelot like wo_lot_rcpt no-undo.

define new shared variable msgref as character format "x(20)".
define shared variable multi_entry as log no-undo.
define shared variable cline as character.
define shared variable lotserial_control like pt_lot_ser.
define shared variable issue_or_receipt as character.
define shared variable total_lotserial_qty like sr_qty.
define shared variable site like sr_site no-undo.
define shared variable location like sr_loc no-undo.
define shared variable lotserial like sr_lotser no-undo.
define shared variable lotserial_qty like sr_qty no-undo.
define shared variable trans_um like pt_um.
define shared variable trans_conv like sod_um_conv.
define shared variable transtype as character.
define shared variable lotref like sr_ref no-undo.

define variable sr_recno as recid.
define variable del-yn like mfc_logical.
define variable num_recs as integer.
define variable rec_indx as integer.
define variable undo-input like mfc_logical.
define variable i as integer.
define variable j as integer.
define variable iiii as integer.
define variable serialcount as integer.
define variable serials_yn like mfc_logical.
define variable nextserial as integer.
define variable serialprefix as character.
define variable serialsuffix as character.
define variable intstart as integer.
define variable intend as integer.
define variable seriallength as integer.
define variable intcount as integer.
define variable iss_yn like mfc_logical.
define variable newlot like wo_lot_next.
define variable trans-ok like mfc_logical.
define variable alm_recno as recid.
define variable getlot like mfc_logical.
define variable frametitle as character no-undo.
define variable l_addon like mfc_logical initial yes no-undo.
define variable l_count as integer no-undo.

FORM /*GUI*/ 
   sr_site
   sr_loc
   sr_lotser
   sr_ref
   sr_qty
with down frame c overlay title color normal frametitle THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

find first clc_ctrl no-lock no-error.
if not available clc_ctrl then do:
   {gprun.i ""gpclccrt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   find first clc_ctrl no-lock.
end.

find pt_mstr no-lock where pt_part = global_part no-error.

pause 0.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   space(1)
   site
   location
   lotserial
   lotref
   lotserial_qty
   space(1)
         space(6)   
with frame a column 5 attr-space overlay no-underline
   /*V8+*/ THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

      frame a:row = frame c:row + frame c:height-chars.   

/* ISSUE-OR-RECEIPT VALUES ARE:                          */
/*  SHIP   : MO SHIPMENTS (OF TOTAL_LOTSERIAL_QTY)       */
/*  RETURN : MO RETURNS (OF TOTAL_LOTSERIAL_QTY)         */
/*  RECEIPT: INVENTORY UNPLANNED RECEIPT (LOTSERIAL_QTY) */
/*  ISSUE  : WORK ORDER ISSUE (OF LOTSERIAL_QTY)         */

if issue_or_receipt = (" " + getTermLabel("RETURN",7)) then
   frametitle = getFrameTitle("RETURN_DETAIL",20) + "- " +
                getTermLabel("QUANTITY",16) + ": " +
                string(total_lotserial_qty) + " " + trans_um + " ".

else
if issue_or_receipt = getTermLabel("RECEIPT",8) then
   frametitle = getFrameTitle("RECEIPT_DETAIL",20) + "- " +
                getTermLabel("QUANTITY",16) + ": " +
                string(lotserial_qty) + " " + trans_um + " ".

else
if issue_or_receipt = getTermLabel("ISSUE",8) then
   frametitle = getFrameTitle("ISSUE_DETAIL",18) + "- " +
                getTermLabel("QUANTITY",16) + ": " +
                string(lotserial_qty) + " " + trans_um + " ".

else
if issue_or_receipt = getTermLabel("SHIP",8) then
   frametitle = getFrameTitle("ISSUE_DETAIL",18) + "- " +
                getTermLabel("QUANTITY",16) + ": " +
                string(total_lotserial_qty) + " " + trans_um + " ".

view frame c.

total_lotserial_qty = 0.
for each sr_wkfl no-lock where
   sr_userid = mfguser and
   sr_lineid = cline:
   /* 'SEO-DEL' IS PUT INTO THE 'TOTAL' RECORD FOR SEO'S (SERVICE   */
   /* ENGINEER ORDERS), HOWEVER, SEO SHIPPING/RETURN LOGIC KNOWS TO */
   /* SKIP THEM...                                                  */
   if sr_rev = "SEO-DEL" then
      next.

   total_lotserial_qty = total_lotserial_qty + sr_qty.
end.

loop1:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   loop2:
   repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

      view.

      clear frame c all no-pause.

      find sr_wkfl where recid(sr_wkfl) = sr_recno no-lock no-error.
      if available sr_wkfl then do:
         do i = 1 to truncate(frame-down(c) / 2,0) while available sr_wkfl:
            find next sr_wkfl
            where sr_userid = mfguser and sr_lineid = cline no-lock no-error.
         end.

         if not available sr_wkfl then
            find last sr_wkfl
            where sr_userid = mfguser and sr_lineid = cline no-lock no-error.

         do i = 1 to frame-down(c) - 1 while available sr_wkfl:
            find prev sr_wkfl
            where sr_userid = mfguser and sr_lineid = cline no-lock no-error.
         end.

         if not available sr_wkfl then
            find first sr_wkfl
            where sr_userid = mfguser and sr_lineid = cline no-lock no-error.
      end.
      else
         find first sr_wkfl
         where sr_userid = mfguser and sr_lineid = cline no-lock no-error.

      if available sr_wkfl then do:
         do i = 1 to frame-down(c) while available sr_wkfl:
            if sr_rev <> "SEO-DEL" then
            display
               space(1)
               sr_site   /* /*V8! space(.2) */ */
               sr_loc    /* /*V8! space(.2) */ */
               sr_lotser /* /*V8! space(.2) */ */
               sr_ref    /* /*V8! space(.2) */ */
               sr_qty /* /*V8! view-as fill-in size 10 by 1 */ */
               space(1)
            with frame c.
            if sr_rev <> "SEO-DEL" then do:
               find next sr_wkfl no-lock
               where sr_userid = mfguser and sr_lineid = cline no-error.

               if frame-line(c) < frame-down(c) then down 1 with frame c.
            end.
            else
            /* DON'T LEAVE AN EXTRA BLANK LINE IN FRAME C */
            find next sr_wkfl no-lock
            where sr_userid = mfguser and sr_lineid = cline no-error.
         end.
      end.

      find sr_wkfl where recid(sr_wkfl) = sr_recno no-lock no-error.

      if not available sr_wkfl then
         find first sr_wkfl
         where sr_userid = mfguser and sr_lineid = cline no-lock no-error.

      if available sr_wkfl then do:
         if sr_rev <> "SEO-DEL" then
            assign
               site = sr_site
               location = sr_loc
               lotserial = sr_lotser
               lotref = sr_ref
               lotserial_qty = sr_qty.
      end.

      /* TOTAL LOT/SERIAL QUANTITY ENTERED */
      {pxmsg.i &MSGNUM=300 &ERRORLEVEL=1 &MSGARG1=total_lotserial_qty}

      idloop:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         getlot = yes.
         if ((pt_lot_ser = "L") and singlelot
            and (lotserial = lotnext and lotnext <> "")
            and (clc_lotlevel <> 0)) then
            getlot = no.
         if (pt_lot_ser = "L" and pt_auto_lot = yes)
            and (lotserial <> "")
            and (not transtype begins "ISS") then
            getlot = no.
         display
            site
            location
            lotserial
            lotserial_qty.
         update
            site
            location
            lotserial when (getlot = yes)
            lotref
         editing:
            global_site = input site.
            global_loc = input location.
            global_lot = input lotserial.

            {mfnp08.i sr_wkfl sr_id
               "sr_userid = mfguser and sr_lineid = cline"
               sr_site "input site" sr_loc "input location"
               sr_lotser "input lotserial" sr_ref "input lotref"}

            if recno <> ? then do:
               assign
                  site = sr_site
                  location = sr_loc
                  lotserial = sr_lotser
                  lotserial_qty = sr_qty
                  lotref = sr_ref.
               display
                  site
                  location
                  lotserial
                  lotref
                  lotserial_qty.
            end.
         end.

         find si_mstr where si_site = site no-lock no-error.
         if not available si_mstr then do:

            /* SITE DOES NOT EXIST */
            {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
            undo idloop, retry.
         end.

         {gprun.i ""gpsiver.p"" "(input  site,
                                  input  ?,
                                  output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:

            /* USER DOES NOT HAVE ACCESS TO THIS SITE*/
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            undo idloop, retry.
         end.

         if singlelot and (lotnext <> lotserial) and
            (pt_lot_ser <> "") and (clc_lotlevel <> 0) then do:
            if (can-find (first lot_mstr where lot_serial = lotserial
               and lot_part = pt_part)) then do:

               /* LOT IS IN USE */
               {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
               undo idloop, retry idloop.
            end.
            find first lotw_wkfl
            where lotw_lotser = lotserial
              and lotw_mfguser <> mfguser
              and lotw_part <> pt_part no-lock no-error.
            if available lotw_wkfl then do:

               /* LOT IS IN USE */
               {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
               undo idloop, retry idloop.
            end.
         end.
         if (pt_lot_ser = "S") and (clc_lotlevel <> 0) then do:
            find first sr_wkfl
            where sr_userid = mfguser
              and sr_lotser = lotserial no-lock no-error.
            if  available sr_wkfl and
               (sr_site <> site or
               sr_lineid <> cline or
               sr_ref <> lotref or
               sr_loc <> location) then do:

               /* LOT IS IN USE */
               {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
               undo idloop, retry idloop.
            end.
         end.

         find sr_wkfl
         where sr_userid = mfguser
           and sr_lineid = cline
           and sr_site = site
           and sr_loc = location
           and sr_lotser = lotserial
           and sr_ref = lotref exclusive-lock no-error.

         if not available sr_wkfl then do:

            /* ADDING NEW RECORD */
            {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

            create sr_wkfl.

            assign
               sr_rev = base_location
               sr_user2 = pt_part
               sr_userid = mfguser
               sr_lineid = cline
               sr_site = site
               sr_loc = location
               sr_lotser = lotserial
               sr_ref = lotref.
            if recid(sr_wkfl) = -1 then .
         end.
         else
            lotserial_qty = sr_qty.

         status input stline[2].

         set lotserial_qty go-on  ("F5" "CTRL-D").

         if lastkey = keycode("F5")
            or lastkey = keycode("CTRL-D") then do:
            del-yn = yes.

            /* PLEASE CONFIRM DELETE */
            {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
            if del-yn = no then
               undo idloop, retry idloop.
            assign
               lotserial_qty = 0
               total_lotserial_qty = total_lotserial_qty - sr_qty.
            delete sr_wkfl.

            find next sr_wkfl
            where sr_userid = mfguser
              and sr_lineid = cline no-lock no-error.

            if not available sr_wkfl then
               find prev sr_wkfl where sr_userid = mfguser
                                   and sr_lineid = cline no-lock no-error.

            if not available sr_wkfl then
               find first sr_wkfl
               where sr_userid = mfguser and sr_lineid = cline no-lock no-error.

            if available sr_wkfl then
               sr_recno = recid(sr_wkfl).
            else
               sr_recno = ?.

            next loop2.
         end.

         if lotserial_qty <> 0 then do:
            serialcount = 1.

            if available pt_mstr and pt_lot_ser = "s"
               and (lotserial_qty > 1 or lotserial_qty < -1) then do:
               serials_yn = yes.

               /* CREATE LIST OF SERIAL NUMBERS */
               {pxmsg.i &MSGNUM=1100 &ERRORLEVEL=1 &CONFIRM=serials_yn}

               if not serials_yn then
                  undo idloop, retry idloop.

               serialcount = if lotserial_qty > 0 then
                                lotserial_qty
                             else
                                - lotserial_qty.

               /* HERE FIGURE OUT WHERE THE LAST INTEGER PORTION OF THE
               SERIAL NUMBER IS */

               assign
                  intstart = ?
                  intend = ?
                  serialprefix = ""
                  serialsuffix = ""
                  i = length(lotserial).

               do while i > 0 and
                  (substring(lotserial,i,1) < "0"
                  or substring(lotserial,i,1) > "9"):
                  i = i - 1.
               end.

               if i = 0 then do:

                  /* UNABLE TO FIND INTEGER PORTION OF SERIAL */
                  {pxmsg.i &MSGNUM=1099 &ERRORLEVEL=3}
                  undo idloop, retry idloop.
               end.

               intend = i.

               do while i > 0 and substring(lotserial,i,1) >= "0"
                  and substring(lotserial,i,1) <= "9":
                  i = i - 1.
               end.

               assign
                  intstart = i + 1.
                  seriallength = intend - intstart + 1.

               if intstart > 1 then
                  serialprefix = substring(lotserial, 1, intstart - 1).

               assign
                  nextserial =
                     integer(substring(lotserial,intstart,seriallength))
                  serialsuffix = substring(lotserial,intend + 1,40)
                  lotserial_qty = lotserial_qty / serialcount.

            end.

            do i = 1 to serialcount:
               if (pt_lot_ser = "S")
                  and (clc_lotlevel <> 0) then do:
                  find first sr_wkfl
                  where sr_userid = mfguser and sr_lotser = lotserial
                  no-lock no-error.
                  if available sr_wkfl
                     and (sr_site <> site or
                     sr_lineid <> cline or
                     sr_ref <> lotref or
                     sr_loc <> location) then do:

                     /* LOT IS IN USE */
                     {pxmsg.i &MSGNUM=2759 &ERRORLEVEL=3}
                     undo idloop, retry idloop.
                  end.
               end.
               find sr_wkfl
               where sr_userid = mfguser
                 and sr_lineid = cline
                 and sr_site = site
                 and sr_loc = location
                 and sr_lotser = lotserial
                 and sr_ref = lotref no-error.
               if not available sr_wkfl then do:
                  create sr_wkfl.

                  assign
                     sr_rev = base_location
                     sr_user2 = pt_part
                     sr_userid = mfguser
                     sr_lineid = cline
                     sr_site = site
                     sr_loc = location
                     sr_lotser = lotserial
                     sr_ref = lotref.
                  if recid(sr_wkfl) = -1 then .
               end.

               assign
                  total_lotserial_qty = total_lotserial_qty - sr_qty
                  sr_qty = lotserial_qty
                  total_lotserial_qty = total_lotserial_qty + sr_qty.

               /*Convert quantity to stocking unit of measure */
               if i = 1 then do:
                  {gprun.i ""icedit.p"" "(transtype,
                                          site,
                                          location,
                                          pt_part,
                                          lotserial,
                                          lotref,
                                          lotserial_qty * trans_conv,
                                          trans_um,
                                          trnbr,
                                          trline,
                                          output undo-input)" }
/*GUI*/ if global-beam-me-up then undo, leave.


                  if undo-input then undo idloop, retry idloop.

                  /* VALIDATE GRADE ASSAY EXPIRE & INVENTORY STATUS*/
                  {gprun.i ""repkisc.p"" "(input site,
                                           input base_site,
                                           input location,
                                           input base_location,
                                           input pt_part,
                                           input lotserial,
                                           input lotref,
                                           input lotserial_qty * trans_conv,
                                           input use-to-loc-status,
                                           output undo-input)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  if undo-input then undo idloop, retry idloop.

               end. /* if i = 1 */

               else if lotserial_qty <> 0 then do: /*REFER TO G0SY*/
                  {gprun.i ""icedit3.p"" "(transtype,
                                           site,
                                           location,
                                           pt_part,
                                           lotserial,
                                           lotref,
                                           lotserial_qty * trans_conv,
                                           trans_um,
                                           trnbr,
                                           trline,
                                           output undo-input)" }
/*GUI*/ if global-beam-me-up then undo, leave.

               end.

               if undo-input then undo idloop, retry idloop.

               if base_site <> ? and base_site <> site then do:
                  iss_yn = no.        /*RECEIPT*/
                  if transtype begins "ISS" then
                        iss_yn = yes. /*ISSUE*/

                  {gprun.i ""icedit4.p"" "(transtype,
                                           base_site,
                                           site,
                                           pt_loc,
                                           location,
                                           pt_part,
                                           lotserial,
                                           lotref,
                                           lotserial_qty * trans_conv,
                                           trans_um,
                                           trnbr,
                                           trline,
                                           output undo-input)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  if undo-input then undo idloop, retry idloop.

                  /* VALIDATE GRADE ASSAY EXPIRE & INVENTORY STATUS*/
                  {gprun.i ""repkisc.p"" "(input site,
                                           input base_site,
                                           input location,
                                           input base_location,
                                           input pt_part,
                                           input lotserial,
                                           input lotref,
                                           input lotserial_qty * trans_conv,
                                           input use-to-loc-status,
                                           output undo-input)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               end.

               sr_recno = recid(sr_wkfl).

               if serialcount > 1 then do:

                  /* TO TAKE INTO ACCOUNT OF THE CHANGING FORMAT AND */
                  /* TO GENERATE ERROR MESSAGE ONLY IF THE LENGTH    */
                  /* (LOTSERIAL) EXCEEDS 18 CHARACTERS               */

                  l_addon = yes.
                  do l_count = 0 to 8:
                     if index(string(nextserial),string(l_count)) <> 0 then
                        l_addon = no.
                  end. /* DO l_count = 0 TO 8 */
                  if l_addon and length(string(nextserial)) = seriallength then
                     seriallength = seriallength + 1.

                  assign
                     nextserial = nextserial + 1
                     lotserial = serialprefix
                               + string(nextserial,fill("9",seriallength))
                               + serialsuffix.
               end.
               if length(lotserial) > 18 then do:
                  /* INTEGER PORTION OF SERIAL NOT LONG ENOUGH */
                  {pxmsg.i &MSGNUM=1098 &ERRORLEVEL=3}
                  undo idloop,retry idloop.
               end. /* IF LENGTH (lotserial) */

            end.
            if singlelot then
               lotnext = lotserial.
         end.

         else do:
            assign
               lotserial_qty = 0
               total_lotserial_qty = total_lotserial_qty - sr_qty.
            delete sr_wkfl.

            find next sr_wkfl
            where sr_userid = mfguser and sr_lineid = cline no-lock no-error.

            if not available sr_wkfl then
               find first sr_wkfl
               where sr_userid = mfguser and sr_lineid = cline no-lock no-error.

            if available sr_wkfl then
               sr_recno = recid(sr_wkfl).
            else
               sr_recno = ?.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* idloop */
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* loop2 */

   /* TOTAL LOT/SERIAL QUANTITY ENTERED */
   {pxmsg.i &MSGNUM=300 &ERRORLEVEL=1 &MSGARG1=total_lotserial_qty}

   if not batchrun then do:

      {swindowb.i
         &file=sr_wkfl
         &framename="c"
         &frame-attr="overlay col 5 row 8 attr-space
                      title color normal frametitle"
         &downline=6
         &record-id=sr_recno
         &search=sr_lineid
         &equality=cline
         &other-search="and sr_userid = mfguser"
         &scroll-field=sr_loc
         &create-rec=no
         &assign="sr_userid = mfguser sr_lineid = cline"
         &update-leave=yes
         &s0="/*"
         &display1=sr_site
         &display2=sr_loc
         &display3=sr_lotser
         &display4=sr_ref
         &display5=sr_qty
         }

   end.

   if keyfunction(lastkey) = "end-error" then
      leave.
   if batchrun and keyfunction(lastkey) = "." then
      leave.

end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* loop1: repeat: */

pause 0.
hide frame c.
hide frame a.
